package com.chaosj.webmagic.dto;

import com.chaosj.webmagic.process.*;
import us.codecraft.webmagic.processor.PageProcessor;

/**
 * @className: DisorderDto
 * @description:
 * @author: caoyangjie
 * @date: 2021/8/10
 **/
public enum GitBookHostEnums {
    /**
     * 暂不支持, 需要抓取异步返回数据
     */
    BOOK_STACK_CN("https://www.bookstack.cn/", BookStackProcess.class, true),
    UNKNOWN("UNKNOWN", UnkownScrapeProcess.class, false),
    ;

    private String url;
    private Class proccess;
    private boolean loginFlag;

    GitBookHostEnums(String url, Class process, boolean needLogin){
        this.url = url;
        this.proccess = process;
        this.loginFlag = needLogin;
    }

    public String getUrl() {
        return url;
    }

    public Class<PageProcessor> getProccess(){
        return proccess;
    }

    public boolean loginFlag(){
        return loginFlag;
    }

    public static GitBookHostEnums position(String uri) {
        GitBookHostEnums[] values = GitBookHostEnums.values();
        for (GitBookHostEnums value : values) {
            if (uri.contains(value.getUrl().replace("https://",""))) {
                return value;
            }
        }
        return UNKNOWN;
    }
}
